unit datamodule_frm;

{$mode objfpc}{$H+}

interface

uses
  Classes, SysUtils, FileUtil, LResources, Forms, Controls, Dialogs, LR_Class,
  LR_DBSet, LR_ChBox, ZConnection, ZDataset, inifiles, db;

type

  { TDataModule1 }

  TDataModule1 = class(TDataModule)
    ds_report1: TDatasource;
    repds3: TfrDBDataSet;
    repds4: TfrDBDataSet;
    frReport1: TfrReport;
    repds1: TfrDBDataSet;
    repds2: TfrDBDataSet;
    ZConnection1: TZConnection;
    zq_report1: TZReadOnlyQuery;
    zq_report2: TZReadOnlyQuery;
    zq_rep3: TZReadOnlyQuery;
    zq_rep4: TZReadOnlyQuery;
    function GetValueIniFile( sezione,parametro:String;fileINI:AnsiString):String;
    procedure DataModuleCreate(Sender: TObject);
  private
    { private declarations }
  public
    { public declarations }
    username:string;
    idutente,idditta:integer;
  end; 

var
  DataModule1: TDataModule1;

implementation

{ TDataModule1 }

function Tdatamodule1.GetValueIniFile(sezione,parametro:String;fileINI:AnsiString):String;
var settings: TIniFile;
begin
     //Apro il file Ini
     settings := TIniFile.Create(fileINI);
     //Se il parametro indicato esiste ritorna il suo valore,
     //altrimenti ritorna una stringa vuota
     if settings.ValueExists(sezione,parametro) then
        GetValueIniFile:=settings.ReadString(sezione,parametro,'')
     else
        GetValueIniFile:='';
     //Libera la memoria assegnata all'istanza settings della classe TIniFile.
     settings.Free;
end;

procedure TDataModule1.DataModuleCreate(Sender: TObject);
var PathIniFile: AnsiString; {  flagDatiOk:Boolean;}
begin
     //importo la configurazione del db dal file ini
     PathIniFile := ProgramDirectory + 'settings.ini';
     ZConnection1.User:=GetValueIniFile('database','user',PathIniFile);
     ZConnection1.Password:=GetValueIniFile('database','password',PathIniFile);
     ZConnection1.HostName:=GetValueIniFile('database','hostname',PathIniFile);
     ZConnection1.Database:=GetValueIniFile('database','database',PathIniFile);
     ZConnection1.Protocol:=GetValueIniFile('database','protocollo',PathIniFile);
     //assegno i valori predefiniti alle variabili
     username:='';
end;

initialization
  {$I datamodule_frm.lrs}

end.

